﻿using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MvcSample.Infrastructure.TagHelpers
{
    [HtmlTargetElement("email-replace")]
    public class EmailReplaceTagHelper
        :TagHelper
    {
        public string MailTo { get; set; }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "a";
            //if (output.Attributes.TryGetAttribute("mailto", out TagHelperAttribute attr))
            //{
            //    var val = attr.Value;
            //    output.Attributes.SetAttribute("href",$"mailto:{val}");
            //    output.Content.SetContent(val.ToString());
            //} 
            output.Attributes.SetAttribute("href", $"mailto:{MailTo}");
            output.Content.SetContent(MailTo);

        }
    }
}
